
jQuery(document).ready(function() {

    /*
        *--------------------------------------------------------------------------
            1.Easytabs
            2.Contact Form - jQuery Validate and jQuery Form 
            3.Isotope Portfolio Filter
            4.Back to Top
            5.Google Maps
            6.Sidebar Menu
            7.Loading Skills Experince
            8.Get Lastest Tweets And Use jQuery Cycle
        *--------------------------------------------------------------------------
    */


    /* --------------------------------------------------------------------------- */
    /*  1.Easytabs
    /* --------------------------------------------------------------------------- */

    var $content  = $("#content");

    $content.easytabs({
        tabs                : " > div > nav > ul > li",
        animate             : true,
        updateHash          : true,
        animationSpeed      :'normal',
    });



    /* --------------------------------------------------------------------------- */
    /*    2.Contact Form
    /* --------------------------------------------------------------------------- */

    var $contactform  = $('#contact-form'),
        $success      = '<strong>Success!</strong> Your message was sent.';

    // Validate form on keyup and submit
    $contactform.validate({
        rules: {
            name: {
                required    : true,
                minlength   : 2
            },
            email: {
                required    : true,
                email       : true
            },
            message: {
                required    : true,
                minlength   : 10
            },
            website: {
                url: true
            }
        },
        messages: {
            name: {
                required    : "Please enter your name.",
                minlength   : jQuery.format("Your name needs to be at least {0} characters")
            },
            email: {
                required    : "Please enter your email address.",
                minlength   : "You entered an invalid email address."
            },
            website: {
                url         : "website is not valid" 
            },
            message: {
                required    : "Please enter a message.",
                minlength   : jQuery.format("Enter at least {0} characters")
            }
        },


        // submit form - jquery form
        submitHandler: function(form) {
          $(form).ajaxSubmit({
            success: function(responseText, statusText, xhr, $form) {
                        response = '<div class="alert success">'+ $success +'</div>';
                        $(".error,.success").remove();
                        $contactform.prepend(response);
                    },
            error: function(responseText, statusText, xhr, $form){
                        response = '<div class="error">'+ msg +'</div>';
                        $(".error,.success").remove();
                        $contactform.prepend(response);
            }
          });
          return false;
        }
        
    });



    /*----------------------------------------------------*/
    /*  3.Isotope Portfolio Filter
    /*----------------------------------------------------*/

    (function() {

        // Portfolio settings
        var $container          = $('.project-feed');
        var $filter             = $('.project-feed-filter');


        

        // Filter items when filter link is clicked
        $filter.find('a').click(function() {
            var selector = $(this).attr('data-filter');
            $filter.find('a').removeClass('current');
            $(this).addClass('current');
            $container.isotope({ 
                filter             : selector,
                animationOptions   : {
                animationDuration  : 750,
                easing             : 'linear',
                queue              : false,
                }
            });
            return false;
        });




    })();


    /* --------------------------------------------------------------------------- */
    /*  4. Back to Top
    /* --------------------------------------------------------------------------- */

    $("#back-top").hide();
    
    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {
            $('#back-top').fadeIn();
        } else {
            $('#back-top').fadeOut();
        }
    });

    $('#back-top a').click(function () {
        $('body,html').animate({
            scrollTop: 0
        }, 600);
        return false;
    });





    /* --------------------------------------------------------------------------- */
    /*  5.Google Maps
    /* --------------------------------------------------------------------------- */

    var $latlng             = new google.maps.LatLng(21.039966,105.840883),
        $myOptions          = {
            zoom            : 16,
            center          : $latlng,
            panControl      : false,
            zoomControl     : true,
            scaleControl    : false,
            mapTypeControl  : false,
            mapTypeId       : google.maps.MapTypeId.ROADMAP
        },
        $tabContact         = ('tab-contact');

    $content.bind('easytabs:after', function(evt,tab,panel) {
        if ( tab.hasClass($tabContact) ) {
            var $map = new google.maps.Map(document.getElementById("map"), $myOptions);
            var marker = new google.maps.Marker({
                position: $latlng,
                map: $map, 
                title: ""
            });
        }
    });


    /*
    *-----------------------------
        6.Sidebar Menu
    *-----------------------------
    */

    var $mainMenu = $("#sidebar-menu"),
        $cMainMenu = $(".sidebar-menu");


	$(window).scroll(function() {
        var pos = $(this).scrollTop(), 
            width = $(this).width();

        /* show menu items */
        if (pos >= 200 && width > 608) {
            $mainMenu.removeClass('hidden');
             $cMainMenu.css({top: pos + 100});
        } else {
            $mainMenu.addClass('hidden');
        }
    });

    $(window).resize(function(){
        var width = $(this).width();
        if(width < 608)
        {
             $mainMenu.addClass('hidden');
        }
    })


    /*
    *-----------------------------
        7.Loading Skills Experince
    *-----------------------------
    */

    var $skillBar = $(".skillbar");

    $skillBar.each(function(){
    $(this).find('.skillbar-bar').animate({
        width:jQuery(this).attr('data-percent')
    },6000);
    });



    /* 
    *--------------------------------------------------------
        8.Get Lastest Tweets And Use jQuery Cycle
    *---------------------------------------------------------
    */
    
    var $Tweets = $("#tweets");
        $wallCycle = $("#tweets ul");
        
    if($Tweets.length > 0) {
        $Tweets.bind("loaded", function() {
             $wallCycle.cycle({
                fx: 'fade',
                timeout: 2000,
                speed: 400,
                slides: "> li"
            });
        });

        $Tweets.tweet({
            modpath: 'twitter/',
            count: 2,
            loading_text: '<p>loading Tweet...</p>',
            username: 'hoa_doi_2911',
            template: '<small>{time}</small><p>{text}</p>'
        });
    }
});

  